<!--项目附件上传/-->
<template>
  <div class="app-container-add">
    <el-row :gutter="10" class="button-wrap">
      <el-col :span="1.5">
        <el-button icon="el-icon-arrow-left" size="middle" @click="handleReturn()">返回</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-clickForbidden icon="el-icon-document-checked" size="middle" @click="handleSave">保存</el-button>
      </el-col>
    </el-row>
    <div ref="mainCont" class="main-content">
      <el-card class="box-card" shadow="never">
        <div slot="header" class="clearfix">
          <span>项目附件上传</span>
        </div>
        <div class="main-content-body">
          <el-form
            ref="addForm"
            class="dialog-form"
            :model="formData"
            :rules="rules"
            label-width="90px"
          >
            <el-form-item label="勘察任务书" prop="surveySpecificationList">
              <FileUplode
                ref="fileUplode"
                :edit-file-list="surveySpecificationList"
                :status="status"
                @getFileList="getAssignmentBook"
              />
            </el-form-item>
            <el-form-item label="勘察纲要" prop="investigationList">
              <FileUplode
                ref="fileUplode"
                :edit-file-list="investigationList"
                :status="status"
                @getFileList="getOutline"
              />
            </el-form-item>
            <el-form-item label="布孔图" prop="boreholePatternList">
              <FileUplode
                ref="fileUplode"
                :edit-file-list="boreholePatternList"
                :status="status"
                @getFileList="getBoreholePattern"
              />
            </el-form-item>
            <el-form-item label="总平图" prop="soheiMapList">
              <FileUplode
                ref="fileUplode"
                :edit-file-list="soheiMapList"
                :status="status"
                @getFileList="getSoheiMap"
              />
            </el-form-item>
          </el-form>
        </div>
      </el-card>
    </div>

  </div>
</template>

<script>
import { getAttachment } from '@/api/projectManage/project'
import { updateContract } from '@/api/projectManage/project/projectFile'
// 上传文件
import FileUplode from '@/components/Upload/FileUplode'
export default {
  name: 'ProjectFile',
  components: {
    FileUplode
  },
  data() {
    return {
      status: '',
      /* 新增 start*/
      formData: { // 新增数据
        id: '', // 项目id
        surveySpecificationList: [], // 勘察任务书（委托书）
        investigationList: [], // 勘察纲要
        boreholePatternList: [], // 布孔图
        soheiMapList: [] // 总平图
      },
      surveySpecificationList: [], // 回显勘察任务书
      investigationList: [], // 回显勘察纲要
      boreholePatternList: [], // 回显布孔图
      soheiMapList: [], // 回显总平图
      // 表单校验
      rules: {

      }
      /* 新增 end*/
    }
  },
  mounted() {
    // 新增/编辑
    const { id } = this.$route.query
    this.formData.id = id
    this.handleDetail(id)
  },
  methods: {
    async handleDetail(id) {
      const { data } = await getAttachment(id)
      if (data) {
        const { surveySpecification, investigation, boreholePattern, soheiMap } = data
        this.formData = { ...this.formData, surveySpecification, investigation, boreholePattern, soheiMap }
        this.surveySpecificationList = data.surveySpecificationList
        this.investigationList = data.investigationList
        this.boreholePatternList = data.boreholePatternList
        this.soheiMapList = data.soheiMapList
      }
    },
    // 勘察任务书
    getAssignmentBook(fileList, deleteFileIds) {
      this.formData.surveySpecificationList = fileList
    },
    // 勘察纲要
    getOutline(fileList, deleteFileIds) {
      this.formData.investigationList = fileList
    },
    // 勘察报告
    getBoreholePattern(fileList, deleteFileIds) {
      this.formData.boreholePatternList = fileList
    },
    getSoheiMap(fileList, deleteFileIds) {
      this.formData.soheiMapList = fileList
    },
    // 保存
    handleSave() {
      this.$refs.addForm.validate(valid => {
        if (valid) {
          updateContract(this.formData).then(res => {
            if (res) {
              this.msgSuccess('保存成功!')
              this.handleReturn()
            }
          })
        }
      })
    },
    // 返回
    handleReturn() {
      this.$router.go(-1)
    }
    /* 新增/编辑弹层 end*/
  }
}
</script>

<style lang="scss">

.area-wrap {
  margin-bottom: 30px;
  .el-form-item  > .el-form-item__content {
    margin-left: 10px !important;
  }
  .agreement {
  color: #1890ff;
  }
}
</style>
